﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class HotelDetails
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Not Request.QueryString("hid") Is Nothing Then

                Dim txt As Array
                txt = RetriveData("select Id, Name, Description from ptn_Hotels where Id=" & Request.QueryString("hid"), 2)
                ltrTitle.Text = "<h2>" & txt(1) & "</h2>"
                ltrDescription.Text = Server.HtmlDecode(txt(2))

                ltrCost.Text = getCost(Request.QueryString("hid"))

                Fill_dtList(dlImages, "select g.* from ptn_Gallery g inner join ptn_HotelGallery hg on hg.GalleryId=g.Id where IsActive=1 and hg.HotelId=" & Request.QueryString("hid"))
                If dlImages.Items.Count = 0 Then
                    lblImages.Visible = True
                    lblImages.Text = "<b>No images available.</b>"
                End If
                plHotelsList.Visible = False
                plHotelDetails.Visible = True
            Else
                plHotelsList.Visible = True
                plHotelDetails.Visible = False
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Function getCost(ByVal Id As Integer)
        Try
            Dim stroutput As New StringBuilder
            Dim strSql As String = ""
            Dim count As Integer = 0
            Dim i As Integer = 0
            Dim dt As DataTable
            dt = Fill_Table("SELECT distinct rc.Id,rc.Name FROM ptn_RoomCategory rc inner join ptn_HotelCost hc on hc.RoomCategoryId=rc.Id where rc.IsActive=1 and hc.HotelId=" & Id & " and hc.Cost<>''", "RoomCategory")

            stroutput.Append("<table cellpadding=""3"" cellspacing=""0"" align=""center"" width=""100%"">")
            For Each dr As DataRow In dt.Rows

                stroutput.Append("<tr><td valign=""top"">")
                stroutput.Append("<table width=""100%"" cellspacing=""0"" cellpadding=""5"" border=""0"" class=""tablebg"">")
                If i = 0 Then
                    stroutput.Append("<tr>")
                    stroutput.Append("<td valign=""top"" width=""15%""><strong>Property Type<br />(Meal Type)</strong></td>")
                    stroutput.Append("<td valign=""top""><strong>Rates</strong></td>")
                    stroutput.Append("</tr>")
                End If
                stroutput.Append("<tr class=""trBg""><td valign=""middle"" width=""15%"" colspan=""2"">")

                stroutput.Append("<div>")

                stroutput.Append("<div class=""subhead"">" & dr.Item("Name").ToString() & "</div>")

                Dim dtMeal As DataTable
                dtMeal = Fill_Table("SELECT distinct mc.Id,mc.Name,mc.Summary,mc.IsActive FROM ptn_MealType mc inner join ptn_HotelCost hc on hc.MealType=mc.Id where mc.IsActive=1 and hc.HotelId=" & Id & " and hc.RoomCategoryId=" & dr.Item("Id").ToString, "MealType")
                For Each drMeal As DataRow In dtMeal.Rows
                    stroutput.Append("<div>")
                    stroutput.Append("<div class=""boxMeal"">")
                    stroutput.Append(drMeal.Item("Name").ToString())
                    stroutput.Append("</div>")

                    Dim dtCost As DataTable

                    Dim strClient As String
                    If Session("Client") Is Nothing Then
                        strClient = "b2c"
                    Else
                        strClient = Session("Client")
                    End If
                    dtCost = Fill_Table("select hc.*, rt.Name from ptn_hotelcost hc inner join ptn_roomtype rt on rt.id=hc.roomtypeid where hc.hotelid=" & Id & " and hc.roomcategoryid=" & dr.Item("Id").ToString & " and hc.mealtype=" & drMeal.Item("Id").ToString & " and clienttype='" & strClient & "' and (getdate() between startdate and enddate) order by startdate desc, enddate desc", "HotelCost")
                    stroutput.Append("<table cellpadding=""2"" cellspacing=""2""><tr><td width=""480px"">")
                    For Each drCost As DataRow In dtCost.Rows
                        stroutput.Append("<div class=""box80"">")
                        stroutput.Append("<div><b>" & drCost.Item("Name").ToString() & "</b></div>")
                        stroutput.Append("<div class=""price"">" & formatPrice(drCost.Item("Cost").ToString()) & "</div>")
                        stroutput.Append("</div>")
                        count = count + 1
                    Next

                    stroutput.Append("</td>")
                    stroutput.Append("<td valign=""middle""><a href=""BookHotel.aspx?id=" & Id & "&cid=" & dr.Item("Id").ToString & "&mid=" & drMeal.Item("Id").ToString & """ class=""form-button"">Book Now</a></td>")
                    stroutput.Append("</tr></table>")

                    stroutput.Append("<div class=""clear""></div>")
                    stroutput.Append("</div>")
                Next


                stroutput.Append("<div class=""clear""></div>")
                stroutput.Append("</div>")

                stroutput.Append("</td>")
                stroutput.Append("</tr>")
                stroutput.Append("</table>")


                stroutput.Append("</td></tr>")

                i = i + 1
            Next
            If i = 0 Or count = 0 Then
                Dim strSub As String
                If Not Request.QueryString("Id") Is Nothing Then
                    Dim txt As Array
                    txt = RetriveData("select Name, City from ptn_Hotels where Id=" & Request.QueryString("Id"), 1)
                    strSub = txt(0) & " (" & txt(1) & ")"
                Else
                    strSub = "Hotel"
                End If
                stroutput.Remove(0, stroutput.Length)
                stroutput.Append("<div class=""subhead"">Send a Request on <a href=""mailto:enquiry@philatourism.com?Subject=Request for " & strSub & """>enquiry@philatourism.com</a></div>")
            End If
            stroutput.Append("</table>")
            Return stroutput.ToString
        Catch ex As Exception
            Return "No records found."
        End Try
    End Function

    Protected Function fillGallery(ByVal Id As Integer)
        Dim str As New StringBuilder
        Dim dt As New DataTable
        Dim count As Integer = 0
        dt = Fill_Table("select g.* from ptn_Gallery g inner join ptn_HotelGallery hg on hg.GalleryId=g.Id where g.IsActive=1 and hg.HotelId=" & Id, "Gallery")
        str.Append("<table cellspacing=""3"" cellpadding=""2"" align=""center""><tr>")
        For Each dr As DataRow In dt.Rows
            If count = 4 Then
                str.Append("</tr><tr>")
                count = 0
            End If
            str.Append("<td width=""25%"" align=""center"" class=""galimg"">")
            str.Append("<a href=""images/" & dr.Item("Image").ToString & """ rel=""lightbox[" & Id & "]"" title=""" & dr.Item("Caption").ToString & """><img src=""images/" & dr.Item("Thumbnail").ToString & """ /></a>")
            str.Append("<td>")
            count = count + 1
        Next
        If count = 1 Then
            str.Append("<td width=""25%"">&nbsp;</td>")
            str.Append("<td width=""25%"">&nbsp;</td>")
            str.Append("<td width=""25%"">&nbsp;</td>")
        ElseIf count = 2 Then
            str.Append("<td width=""25%"">&nbsp;</td>")
            str.Append("<td width=""25%"">&nbsp;</td>")
        ElseIf count = 3 Then
            str.Append("<td width=""25%"">&nbsp;</td>")
        End If
        str.Append("</tr></table>")
        Return str.ToString
    End Function

End Class